package iomonitor

import (
	"github.com/shirou/gopsutil/v3/disk"
	"github.com/shirou/gopsutil/v3/net"
	monproto "gollect/proto"
	"time"
)

func Collect(interval time.Duration) (*monproto.DiskInfo, *monproto.NetworkInfo) {
	diskIO, err := disk.IOCounters()
	var totalRead, totalWrite uint64
	if err == nil {
		for _, io := range diskIO {
			totalRead += io.ReadBytes
			totalWrite += io.WriteBytes
		}
	}
	netIO, err := net.IOCounters(true)
	var totalSent, totalRecv uint64
	if err == nil {
		for _, io := range netIO {
			totalSent += io.BytesSent
			totalRecv += io.BytesRecv
		}
	}
	return &monproto.DiskInfo{
		TotalReadBytes:  totalRead,
		TotalWriteBytes: totalWrite,
	}, &monproto.NetworkInfo{
		TotalBytesSent: totalSent,
		TotalBytesRecv: totalRecv,
	}
} 